 clear all
 
 

use "Estimation Sample.dta" 


tab loading_kg
replace loading_kg="" if loading_kg=="n.a."
replace loading_kg="" if loading_kg=="unknown"
destring loading_kg, replace





*Note: These identifiers equal one even in years in which a product is not sold in the respective country (AT, HU, HR), but enters the country later.

**Identifier for all refrigerators/freezers sold in Austria and elsewhere 
**2009
gen a9=0
replace a9=1 if country=="Austria" & (category=="refrigerator"|category=="freezer") & year==2009
by id, sort: egen suma9=sum(a9)
gen aff9=0
replace aff9=1 if suma9>0

**2010
gen a10=0
replace a10=1 if country=="Austria" & (category=="refrigerator"|category=="freezer") & year==2010
by id, sort: egen suma10=sum(a10)
gen aff10=0
replace aff10=1 if suma10>0

**Identifier for all refrigerators/freezers sold in Hungary and elsewhere
gen h=0
replace h=1 if country=="Hungary" & (category=="refrigerator"|category=="freezer")& year==2016
by id, sort: egen sumh=sum(h)
gen hff=0
replace hff=1 if sumh>0

**Identifier for all refrigerators/freezers sold in Croatia and elsewhere
gen c=0
replace c=1 if country=="Croatia" & (category=="refrigerator"|category=="freezer")& year==2015
by id, sort: egen sumc=sum(c)
gen cff=0
replace cff=1 if sumc>0

**Identifier for all washing machines sold in Austria and elsewhere
gen a1=0
replace a1=1 if country=="Austria" & (category=="washing machine")&year==2010
by id, sort: egen suma1=sum(a1)
gen aw=0
replace aw=1 if suma1>0

**Identifier for all washing machines sold in Hungary and elsewhere
gen h1=0
replace h1=1 if country=="Hungary" & (category=="washing machine")& year==2015
by id, sort: egen sumh1=sum(h1)
gen hw=0
replace hw=1 if sumh1>0

**Identifier for all washing machines sold in Croatia and elsewhere
gen c1=0
replace c1=1 if country=="Croatia" & (category=="washing machine")& year==2015
by id, sort: egen sumc1=sum(c1)
gen cw=0
replace cw=1 if sumc1>0

**Austria, 2009 REF/FRZ program
preserve
keep if country=="Austria"
keep if (category=="refrigerator"|category=="freezer")

**kWh
egen 		median_all			=median(annual_energy_consumption) 			if 				year==2009
egen 		median_treat		=median(annual_energy_consumption) 			if treataf==1 & year==2009
gen 		kwh_rel				=median_treat/median_all				    if treataf==1 & year==2009
sum 		kwh_rel 

**Units
egen 		median_all_units	=median(units)							 	if 					((year==2008 & month>5)|(year==2009 & month<=5)) & aff9==1
egen 		median_treat_units	=median(units)							    if treataf==1 &  	((year==2008 & month>5)|(year==2009 & month<=5))
gen 		units_rel			=median_treat_units/median_all_units	    if treataf==1 & 	((year==2008 & month>5)|(year==2009 & month<=5)) & aff9==1
sum 		units_rel

**Price
egen 		median_all_price	=median(price_eur)							 if 				((year==2008 & month>5)|(year==2009 & month<=5)) & aff9==1
egen 		median_treat_price	=median(price_eur)							 if treataf==1 &  	((year==2008 & month>5)|(year==2009 & month<=5))
gen 		price_rel			=median_treat_price/median_all_price	     if treataf==1 & 	((year==2008 & month>5)|(year==2009 & month<=5)) & aff9==1
sum 		price_rel

**Age
egen 		median_all_age	    =median(mage) 								 if 			 year==2009 
egen 		median_treat_age	=median(mage)								 if treataf==1 & year==2009
gen 		age_rel				=median_treat_age/median_all_age			 if treataf==1 & year==2009	
sum 		age_rel

**Subsidized models fraction of market

egen 		sum_all_units	=sum(units)							 	         if 					((year==2008 & month>5)|(year==2009 & month<=5)) 
egen 		sum_treat_units =sum(units)										 if treataf==1 &		((year==2008 & month>5)|(year==2009 & month<=5))
gen 		fraction		=sum_treat_units/sum_all_units		
sum 		fraction				

restore

***Austria, 2010 REF/FRZ program

preserve
keep if country=="Austria"
keep if (category=="refrigerator"|category=="freezer")

**kWh
egen 		median_all			=median(annual_energy_consumption) 			if 				year==2010
egen 		median_treat		=median(annual_energy_consumption) 			if treataf==1 & year==2010
gen 		kwh_rel				=median_treat/median_all				    if treataf==1 & year==2010
sum 		kwh_rel 

**Units
egen 		median_all_units	=median(units)							 	if 					(year==2010 & month<=5) & aff10==1
egen 		median_treat_units	=median(units)							    if treataf==1 &  	(year==2010 & month<=5)
gen 		units_rel			=median_treat_units/median_all_units	    if treataf==1 & 	(year==2010 & month<=5) & aff10==1
sum 		units_rel

**Price
egen 		median_all_price	=median(price_eur)							 if 				(year==2010 & month<=5) & aff10==1
egen 		median_treat_price	=median(price_eur)							 if treataf==1 &  	(year==2010 & month<=5)
gen 		price_rel			=median_treat_price/median_all_price	     if treataf==1 & 	(year==2010 & month<=5) & aff10==1
sum 		price_rel

**Age
egen 		median_all_age	    =median(mage) 								 if 			  year==2010 
egen 		median_treat_age	=median(mage)								 if treataf==1 & year==2010
gen 		age_rel				=median_treat_age/median_all_age			 if treataf==1 & year==2010	
sum 		age_rel

**Subsidized models fraction of market

egen 		sum_all_units	=sum(units)							 	         if 					(year==2010 & month<=5)
egen 		sum_treat_units =sum(units)										 if treataf==1 &		(year==2010 & month<=5)
gen 		fraction		=sum_treat_units/sum_all_units				
sum 		fraction

restore

***Austria, 2010 WM program

preserve
keep if country=="Austria"
keep if (category=="washing machine")

gen    		kwhkg=annual_energy_consumption/loading_kg

**kWh
egen 		median_all			=median(kwhkg) 								if 			   year==2010
egen 		median_treat		=median(kwhkg) 								if treata==1 & year==2010
gen 		kwh_rel				=median_treat/median_all				    if treata==1 & year==2010
sum 		kwh_rel 

**Units
egen 		median_all_units	=median(units)							 	if 					(year==2009) & aw==1
egen 		median_treat_units	=median(units)							    if treata==1 &  	(year==2009)
gen 		units_rel			=median_treat_units/median_all_units	    if treata==1 & 	    (year==2009) & aw==1
sum 		units_rel

**Price
egen 		median_all_price	=median(price_eur)							 if 				(year==2009) & aw==1
egen 		median_treat_price	=median(price_eur)							 if treata==1 &  	(year==2009)
gen 		price_rel			=median_treat_price/median_all_price	     if treata==1 & 	(year==2009) & aw==1
sum 		price_rel

**Age
egen 		median_all_age	    =median(mage) 								 if 			year==2010 
egen 		median_treat_age	=median(mage)								 if treata==1 & year==2010
gen 		age_rel				=median_treat_age/median_all_age			 if treata==1 & year==2010	
sum 		age_rel

egen 		sum_all_units	=sum(units)							 	         if 				(year==2009)
egen 		sum_treat_units =sum(units)										 if treata==1 &		(year==2009)
gen 		fraction		=sum_treat_units/sum_all_units				
sum 		fraction

restore


***Hungary, 2016 REF/FRZ program

***A+++
preserve
keep if country=="Hungary"
keep if (category=="refrigerator"|category=="freezer")

**kWh
egen 		median_all			=median(annual_energy_consumption) 			if 				year==2016
egen 		median_treat_3		=median(annual_energy_consumption) 			if treathf==1 & year==2016 & energy_label_eu=="A+++"
gen 		kwh_rel_3			=median_treat_3/median_all				    if treathf==1 & year==2016 & energy_label_eu=="A+++"
sum 		kwh_rel_3 

egen 		median_treat_2		=median(annual_energy_consumption) 			if treathf==1 & year==2016 & energy_label_eu=="A++"
gen 		kwh_rel_2			=median_treat_2/median_all				    if treathf==1 & year==2016 & energy_label_eu=="A++"
sum 		kwh_rel_2

egen 		median_treat_1		=median(annual_energy_consumption) 			if treathf==1 & year==2016 & energy_label_eu=="A+"
gen 		kwh_rel_1			=median_treat_1/median_all				    if treathf==1 & year==2016 & energy_label_eu=="A+"
sum 		kwh_rel_1

**Units
egen 		median_all_units	=median(units)							 	if 					((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1
egen 		median_treat_units_3=median(units)							    if treathf==1 &  	((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+++"
gen 		units_rel_3			=median_treat_units_3/median_all_units	    if treathf==1 & 	((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1 & energy_label_eu=="A+++"
sum 		units_rel_3

egen 		median_treat_units_2=median(units)							    if treathf==1 &  	((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A++"
gen 		units_rel_2			=median_treat_units_2/median_all_units	    if treathf==1 & 	((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1 & energy_label_eu=="A++"
sum 		units_rel_2

egen 		median_treat_units_1=median(units)							    if treathf==1 &  	((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+"
gen 		units_rel_1			=median_treat_units_1/median_all_units	    if treathf==1 & 	((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1& energy_label_eu=="A+"
sum 		units_rel_1

**Price
egen 		median_all_price	=median(price_eur)							 if 				((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1
egen 		median_treat_price_3=median(price_eur)							 if treathf==1 &  	((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+++"
gen 		price_rel_3			=median_treat_price_3/median_all_price	     if treathf==1 & 	((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1 & energy_label_eu=="A+++"
sum 		price_rel_3

egen 		median_treat_price_2=median(price_eur)							 if treathf==1 &  	((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A++"
gen 		price_rel_2			=median_treat_price_2/median_all_price	     if treathf==1 & 	((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1 & energy_label_eu=="A++"
sum 		price_rel_2

egen 		median_treat_price_1	=median(price_eur)						 if treathf==1 &  	((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+"
gen 		price_rel_1			=median_treat_price_1/median_all_price	     if treathf==1 & 	((year==2015 & month>5)|(year==2016 & month<=5)) & hff==1 & energy_label_eu=="A+"
sum 		price_rel_1


**Age
egen 		median_all_age	    =median(mage) 								 if 			 year==2016 
egen 		median_treat_age_3	=median(mage)								 if treathf==1 & year==2016  & energy_label_eu=="A+++"
gen 		age_rel_3			=median_treat_age_3/median_all_age			 if treathf==1 & year==2016	 & energy_label_eu=="A+++"
sum 		age_rel_3

egen 		median_treat_age_2	=median(mage)								 if treathf==1 & year==2016  & energy_label_eu=="A++"
gen 		age_rel_2			=median_treat_age_2/median_all_age			 if treathf==1 & year==2016	 & energy_label_eu=="A++"
sum 		age_rel_2
 
egen 		median_treat_age_1	=median(mage)								 if treathf==1 & year==2016  & energy_label_eu=="A+"
gen 		age_rel_1			=median_treat_age_1/median_all_age			 if treathf==1 & year==2016	 & energy_label_eu=="A+"
sum 		age_rel_1

**Fraction treated from total market
egen 		sum_all_units	=sum(units)							 	         if 					((year==2015 & month>5)|(year==2016 & month<=5))
egen 		sum_treat_units_3=sum(units)									 if treathf==1 &		((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+++"
gen 		fraction_3		=sum_treat_units_3/sum_all_units				 if treathf==1 &		((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+++"

egen 		sum_treat_units_2=sum(units)									 if treathf==1 &		((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A++"
gen 		fraction_2		=sum_treat_units_2/sum_all_units				 if treathf==1 &		((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A++"

egen 		sum_treat_units_1=sum(units)									 if treathf==1 &		((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+"
gen 		fraction_1		=sum_treat_units_1/sum_all_units				 if treathf==1 &		((year==2015 & month>5)|(year==2016 & month<=5)) & energy_label_eu=="A+"
	
sum 		fraction_3
sum 		fraction_2
sum 		fraction_1

restore


***Hungary, 2015 WM program

***A+++
preserve
keep if country=="Hungary"
keep if (category=="washing machine")
gen    		kwhkg=annual_energy_consumption/loading_kg

**kWh
egen 		median_all			=median(kwhkg) 								if 				year==2015
egen 		median_treat_3		=median(kwhkg) 								if treath==1 & year==2015 & energy_label_eu=="A+++"
gen 		kwh_rel_3			=median_treat_3/median_all				    if treath==1 & year==2015 & energy_label_eu=="A+++"
sum 		kwh_rel_3 

egen 		median_treat_2		=median(kwhkg) 								if treath==1 & year==2015 & energy_label_eu=="A++"
gen 		kwh_rel_2			=median_treat_2/median_all				    if treath==1 & year==2015 & energy_label_eu=="A++"
sum 		kwh_rel_2

egen 		median_treat_1		=median(kwhkg) 								if treath==1 & year==2015 & energy_label_eu=="A+"
gen 		kwh_rel_1			=median_treat_1/median_all				    if treath==1 & year==2015 & energy_label_eu=="A+"
sum 		kwh_rel_1

**Units
egen 		median_all_units	=median(units)							 	if 					((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1
egen 		median_treat_units_3=median(units)							    if treath==1 &  	((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+++"
gen 		units_rel_3			=median_treat_units_3/median_all_units	    if treath==1 & 	    ((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1 & energy_label_eu=="A+++"
sum 		units_rel_3

egen 		median_treat_units_2=median(units)							    if treath==1 &  	((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A++"
gen 		units_rel_2			=median_treat_units_2/median_all_units	    if treath==1 & 	    ((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1 & energy_label_eu=="A++"
sum 		units_rel_2

egen 		median_treat_units_1=median(units)							    if treath==1 &  	((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+"
gen 		units_rel_1			=median_treat_units_1/median_all_units	    if treath==1 & 	    ((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1& energy_label_eu=="A+"
sum 		units_rel_1

**Price
egen 		median_all_price	=median(price_eur)							 if 				((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1
egen 		median_treat_price_3=median(price_eur)							 if treath==1 &  	((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+++"
gen 		price_rel_3			=median_treat_price_3/median_all_price	     if treath==1 & 	((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1 & energy_label_eu=="A+++"
sum 		price_rel_3

egen 		median_treat_price_2=median(price_eur)							 if treath==1 &  	((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A++"
gen 		price_rel_2			=median_treat_price_2/median_all_price	     if treath==1 & 	((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1 & energy_label_eu=="A++"
sum 		price_rel_2

egen 		median_treat_price_1	=median(price_eur)						 if treath==1 &  	((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+"
gen 		price_rel_1			=median_treat_price_1/median_all_price	     if treath==1 & 	((year==2014 & month>6)|(year==2015 & month<=6)) & hw==1 & energy_label_eu=="A+"
sum 		price_rel_1


**Age
egen 		median_all_age	    =median(mage) 								 if 			year==2015 
egen 		median_treat_age_3	=median(mage)								 if treath==1 & year==2015  & energy_label_eu=="A+++"
gen 		age_rel_3			=median_treat_age_3/median_all_age			 if treath==1 & year==2015	& energy_label_eu=="A+++"
sum 		age_rel_3

egen 		median_treat_age_2	=median(mage)								 if treath==1 & year==2015  & energy_label_eu=="A++"
gen 		age_rel_2			=median_treat_age_2/median_all_age			 if treath==1 & year==2015	& energy_label_eu=="A++"
sum 		age_rel_2
 
egen 		median_treat_age_1	=median(mage)								 if treath==1 & year==2015  & energy_label_eu=="A+"
gen 		age_rel_1			=median_treat_age_1/median_all_age			 if treath==1 & year==2015	& energy_label_eu=="A+"
sum 		age_rel_1

**Fraction treated from total market

egen 		sum_all_units	=sum(units)							 	         if 				((year==2014 & month>6)|(year==2015 & month<=6))
egen 		sum_treat_units_3=sum(units)									 if treath==1 &		((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+++"
gen 		fraction_3		=sum_treat_units_3/sum_all_units				 if treath==1 &		((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+++"

egen 		sum_treat_units_2=sum(units)									 if treath==1 &		((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A++"
gen 		fraction_2		=sum_treat_units_2/sum_all_units				 if treath==1 &		((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A++"

egen 		sum_treat_units_1=sum(units)									 if treath==1 &		((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+"
gen 		fraction_1		=sum_treat_units_1/sum_all_units				 if treath==1 &		((year==2014 & month>6)|(year==2015 & month<=6)) & energy_label_eu=="A+"
	
sum 		fraction_3
sum 		fraction_2
sum 		fraction_1
	
restore


***Croatia, 2015 REF/FRZ 

preserve
keep if country=="Croatia"
keep if (category=="refrigerator"|category=="freezer")

**kWh
egen 		median_all			=median(annual_energy_consumption) 			if 			   year==2015
egen 		median_treat		=median(annual_energy_consumption) 			if treatc==1 & year==2015
gen 		kwh_rel				=median_treat/median_all				    if treatc==1 & year==2015
sum 		kwh_rel 

**Units
egen 		median_all_units	=median(units)							 	if 					((year==2014 & month>2)|(year==2015 & month<=2)) & cff==1
egen 		median_treat_units	=median(units)							    if treatc==1 &  	((year==2014 & month>2)|(year==2015 & month<=2))
gen 		units_rel			=median_treat_units/median_all_units	    if treatc==1 & 	((year==2014 & month>2)|(year==2015 & month<=2)) & cff==1
sum 		units_rel

**Price
egen 		median_all_price	=median(price_eur)							 if 				((year==2014 & month>2)|(year==2015 & month<=2)) & cff==1
egen 		median_treat_price	=median(price_eur)							 if treatc==1 &  	((year==2014 & month>2)|(year==2015 & month<=2))
gen 		price_rel			=median_treat_price/median_all_price	     if treatc==1 & 	((year==2014 & month>2)|(year==2015 & month<=2)) & cff==1
sum 		price_rel

**Age
egen 		median_all_age	    =median(mage) 								 if 			year==2015
egen 		median_treat_age	=median(mage)								 if treatc==1 & year==2015
gen 		age_rel				=median_treat_age/median_all_age			 if treatc==1 & year==2015	
sum 		age_rel

egen 		sum_all_units	=sum(units)							 	         if 				((year==2014 & month>2)|(year==2015 & month<=2))
egen 		sum_treat_units=sum(units)										 if treatc==1 &	((year==2014 & month>2)|(year==2015 & month<=2))
gen 		fraction		=sum_treat_units/sum_all_units				

sum 		fraction


restore

***Croatia, 2015 WM 

preserve
keep if country=="Croatia"
keep if (category=="washing machine")
gen    		kwhkg=annual_energy_consumption/loading_kg


**kWh
egen 		median_all			=median(kwhkg) 								if 			   year==2015
egen 		median_treat		=median(kwhkg) 								if treatc==1 & year==2015
gen 		kwh_rel				=median_treat/median_all				    if treatc==1 & year==2015
sum 		kwh_rel 

**Units
egen 		median_all_units	=median(units)							 	if 					((year==2014 & month>2)|(year==2015 & month<=2)) & cw==1
egen 		median_treat_units	=median(units)							    if treatc==1 &  	((year==2014 & month>2)|(year==2015 & month<=2))
gen 		units_rel			=median_treat_units/median_all_units	    if treatc==1 & 	((year==2014 & month>2)|(year==2015 & month<=2)) & cw==1
sum 		units_rel

**Price
egen 		median_all_price	=median(price_eur)							 if 				((year==2014 & month>2)|(year==2015 & month<=2)) & cw==1
egen 		median_treat_price	=median(price_eur)							 if treatc==1 &  	((year==2014 & month>2)|(year==2015 & month<=2))
gen 		price_rel			=median_treat_price/median_all_price	     if treatc==1 & 	((year==2014 & month>2)|(year==2015 & month<=2)) & cw==1
sum 		price_rel

**Age
egen 		median_all_age	    =median(mage) 								 if 			year==2015
egen 		median_treat_age	=median(mage)								 if treatc==1 & year==2015
gen 		age_rel				=median_treat_age/median_all_age			 if treatc==1 & year==2015	
sum 		age_rel

egen 		sum_all_units	=sum(units)							 	         if 				((year==2014 & month>2)|(year==2015 & month<=2))
egen 		sum_treat_units=sum(units)										 if treatc==1 &	((year==2014 & month>2)|(year==2015 & month<=2))
gen 		fraction		=sum_treat_units/sum_all_units				
sum 		fraction

restore
